"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Clock_1 = require("./Clock");
const Delayed_1 = require("./Delayed");
class ClockTimer extends Clock_1.default {
    constructor(autoStart = false) {
        super(autoStart);
        this.delayed = [];
    }
    tick() {
        super.tick();
        let i = this.delayed.length;
        while (i--) {
            const delayed = this.delayed[i];
            if (delayed.active) {
                delayed.tick(this.deltaTime);
            }
            else {
                this.delayed.splice(i, 1);
                continue;
            }
        }
    }
    setInterval(handler, time, ...args) {
        const delayed = new Delayed_1.Delayed(handler, args, time, Delayed_1.Type.Interval);
        this.delayed.push(delayed);
        return delayed;
    }
    setTimeout(handler, time, ...args) {
        const delayed = new Delayed_1.Delayed(handler, args, time, Delayed_1.Type.Timeout);
        this.delayed.push(delayed);
        return delayed;
    }
    clear() {
        let i = this.delayed.length;
        while (i--) {
            this.delayed[i].clear();
        }
        this.delayed = [];
    }
}
exports.default = ClockTimer;
